<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
 		<link href="${pageContext.request.contextPath}/assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css"/>       
        <link href="${pageContext.request.contextPath}/assets/css/codemirror.css" rel="stylesheet" />
        <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/ace.min.css" />
        <link rel="stylesheet" href="${pageContext.request.contextPath}/font/css/font-awesome.min.css" />
        
        
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/ace-ie.min.css" />
		<![endif]-->
		<script src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
		<script src="${pageContext.request.contextPath}/assets/js/typeahead-bs2.min.js"></script>   
        <script src="${pageContext.request.contextPath}/js/lrtk.js" type="text/javascript" ></script>		
		<script src="${pageContext.request.contextPath}/assets/js/jquery.dataTables.min.js"></script>
		<script src="${pageContext.request.contextPath}/assets/js/jquery.dataTables.bootstrap.js"></script>
        <script src="${pageContext.request.contextPath}/assets/layer/layer.js" type="text/javascript" ></script>          
        <script type="text/javascript" src="${pageContext.request.contextPath}/Widget/swfupload/swfupload.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/Widget/swfupload/swfupload.queue.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/Widget/swfupload/swfupload.speed.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/Widget/swfupload/handlers.js"></script>
        <script language="javascript" type="text/javascript" src="${pageContext.request.contextPath}/My97DatePicker/WdatePicker.js"></script>
<title>公告管理</title>

	<script type="text/javascript">
	
		$(function(){
			queryNoticeType();
			
		});
		
		//显示广告分类侧栏
		function queryNoticeType(){
			var begin="<li><i class=\"fa fa-image pink \"></i> <a href=\"noticesServlet?noticeType_id=";
			var end="</a></li>";
			var operation={opr:"list",root:"notices_list"};
			var content1="";
			var content2="";
			$.ajax({
				url:"noticeTypeServlet",//请求的url
				data:operation,
				dataType:"json",//服务器返回数据的类型json格式
				success:function(data){
					if(data.length>0){
						$.each(data,function(i,ele){
							content1=content1+begin+ele.noticeType_id+"&opr=list\">"+ele.name+"("+ele.size+")"+end+" ";
							content2=content2+"<option name=\"noticeType_id\" value=\""+ele.noticeType_id+"\">"+ele.name+end+"</option>";
						});
						$("#allType").after(content1);
						$("#category_choose").after(content2);
					}
					else{
						alert("fail");
					}
				}
			});
		}
		
		/* 
			ajax获取表格，但用在datatable时有问题
			
		function queryNotices(){
			var condition={opr:"list"};
			var content="";
			$.ajax({
				url:"noticesServlet",//请求的url
				//'deptno=10&ename=aa'
				data:condition,//发送到服务器的数据
				dataType:"json",//服务器返回数据的类型json格式
				success:function(data){
					if(data.length>0){
						$.each(data,function(i,ele){
							content=content+"<tr><td><label><input type=\"checkbox\" class=\"ace\"><span class=\"lbl\"></span></label></td>"
							content=content+"<td>"+ele.notices_id+"</td>";
							content=content+"<td>"+ele.noticetype.name+"</td>";
							content=content+"<td>"+ele.titles+"</td>";
							content=content+"<td>"+ele.content_msg+"</td>";
							content=content+"<td>"+ele.create_date+"</td>";
							content=content+"<td class=\"td-status\"><span class=\"label label-success radius\">显示</span></td>";
							content=content+" <td class=\"td-manage\">";
							content=content+"<a onClick=\"member_stop(this,\'10001\')\"  href=\"javascript:;\" title=\"停用\"  class=\"btn btn-xs btn-success\"><i class=\"fa fa-check  bigger-120\"></i></a>";
							content=content+"<a title=\"编辑\" onclick=\"member_edit(\'编辑\',\'member-add.html\',\'4\',\'\',\'510\')\" href=\"javascript:;\"  class=\"btn btn-xs btn-info\" ><i class=\"fa fa-edit bigger-120\"></i></a>";
							content=content+" <a title=\"删除\" href=\"javascript:;\"  onclick=\"member_del(this,\'1\')\" class=\"btn btn-xs btn-warning\" ><i class=\"fa fa-trash  bigger-120\"></i></a>";
							content=content+" </td></tr> ";
						});
						$("#notice_tbody").html(content);
					}else{
						alert("fail");
					}
				
				}
			}); 
		} */
		
		$(function(){
			/**全选全不选**/
			 $("input[name='typeId']").click(function(){
		            $("#checkAll").prop("checked",$("input[name='typeId']").length == $("input[name='typeId']:checked").length ? true : false);
		        });
			
			$("#checkAll").click(
			  function(){
			   $("input[name='typeId']").prop("checked",this.checked);
			  }
			);
			
			/**批量删除**/
			$("#deleteByGroup").click(function(){
				var typeId="";
				
				
				if($("input[name='typeId']:checked").length)
					{
						layer.confirm('确认要删除吗？',function(index){
							$("input[name='typeId']:checked").each(function(){
								typeId=typeId+$(this).parents("tr").find(".notices_id").html()+";";
							});
							$("#del_list").val(typeId);
							$("#delopr").val("del");
							//alert($("#del_list").val());
							//alert($("#delopr").val());
							$("#delForm").submit();
							layer.close(index);	
						});
					}
				else
					{
					layer.alert("你未选中任何项",{
			               title: '提示框',				
						icon:1,		
						  });				
					}
				//alert(typeId);
			});
		});
		
		
		function checkMsg()
		{
			if($("#updatenotices").length>0)
			{
				  layer.alert($("#updatenotices").html(),{
	               title: '提示框',				
				icon:1,		
				  });
			}
		}
		
	</script>

</head>

<body onload="checkMsg();">
<div class=" clearfix" id="advertising">
       <div id="scrollsidebar" class="left_Treeview">
    <div class="show_btn" id="rightArrow"><span></span></div>
    <div class="widget-box side_content" >
    <div class="side_title"><a title="隐藏" class="close_btn"><span></span></a></div>
     <div class="side_list">
      <div class="widget-header header-color-green2">
          <h4 class="lighter smaller">公告分类</h4>
      </div>
      <div class="widget-body">
         <ul class="b_P_Sort_list">
             <li id="allType"><i class="orange  fa fa-user-secret"></i><a href="#">全部(${noticeslist.size() })</a></li>
         </ul>
  </div>
  </div>
  </div>  
  </div><div class="Ads_list">
   <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:ovid()" id="ads_add" class="btn btn-warning"><i class="fa fa-plus"></i> 添加公告</a>
        <a href="javascript:ovid()" class="btn btn-danger" id="deleteByGroup" ><i class="fa fa-trash"></i> 批量删除</a>
       </span>
       <span class="r_f">共：<b>${noticeslist.size() }</b>条记录</span>
     </div>
     <div class="Ads_lists">
       <table class="table table-striped table-bordered table-hover" id="sample-table">
		<thead>
		 <tr>
				<th width="25"><label><input type="checkbox" class="ace" id="checkAll" /><span class="lbl"></span></label></th>
				<th width="50px">ID</th>
				<th width="100px">公告分类</th>
				<th width="100px">标题</th>
				<th width="250px">内容</th>
				<th width="200px">发布时间</th>
				<th width="70">状态</th>                
				<th width="250">操作</th>
			</tr>
		</thead>
	<tbody id="notice_tbody">
      <c:if test="${noticeslist!= null && noticeslist.size() > 0}">
          	<c:forEach items="${noticeslist }" var="notices">
          		<tr>
          	    	<td><label><input type="checkbox" class="ace" name="typeId" /><span class="lbl"></span></label></td>
       				<td class="notices_id">${notices.notices_id }</td>
       				<td class="noticetype" >${notices.noticetype.name }<p style="display: none;">${notices.noticetype.noticeType_id }</p></td>
       				<td class="titles">${notices.titles }</td>
       				<td class="content_msg">${notices.content_msg }</td>
       				<td class="create_date">${notices.create_date }</td>
      		 		<td class="td-status"><span class="label label-success radius">未锁定</span></td>
      				<td class="td-manage">
       		 		<a onClick="member_stop(this,'10001')"  href="javascript:;" title="停用"  class="btn btn-xs btn-success"><i class="fa fa-check  bigger-120"></i></a>   
       		 		<a title="编辑" onclick="member_edit(this,'550')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>      
        			<a title="删除" href="javascript:;"  onclick="member_del(this);" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>
       			</td>
      			</tr>
      </c:forEach>
         </c:if> 
    </tbody>
    </table>
     </div>
 </div>
</div>

<!--操作信息-->
<div style="display: none">
	<c:if test="${sessionScope.excuteMsg_notices!=null&&sessionScope.excuteMsg_notices.length()>0 }"><span id="updatenotices">${sessionScope.excuteMsg_notices }</span></c:if>
</div>

<!--批量删除提交-->
<div style="display: none">
	<form action="noticesServlet" method="post" id="delForm">
		<input type="hidden" name="opr" id="delopr" />
		<input type="text" id="del_list" name="del_list" />
	</form>
</div>

<!--单个删除提交-->
<div style="display: none">
	<form action="noticesServlet" method="post" id="delBySingle">
		<input type="hidden" name="opr" value="del" />
		<input type="hidden" name="notices_id" id="delsingleId" />
	</form>
</div>

<!--添加（修改）公告图层-->
<div id="add_ads_style"  style="display:none">
	<form action="noticesServlet" method="post" id="addForm">
	<input type="hidden" name="notices_id" id="notices_id" />
  	<input type="hidden" name="opr" />
	 	<div class="add_adverts">
		 	<ul>
		  		<li>
			  		<label class="label_name">所属分类</label>
			  		<span class="cont_style">
			  		<select class="form-control" id="noticeType_id" name="noticeType_id">
			    	<option value="all" id="category_choose">选择分类</option>
			  		</select></span>
		  		</li>
		  		<li>
		  			<label class="label_name" >添加时间</label>
		  			<input style="height: 25px" class="Wdate" type="text" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:mm:ss'})" name="create_date" id="create_date" /> 
		  		</li>
		  		<li><label class="label_name">公告标题</label>
		  		<span class="cont_style">
		  			<input name="titles" type="text" id="titles"  class="col-xs-10 col-sm-5" style="width:80px" />
		  			</span>
		  		</li>
		  		<li>
		  			<label class="label_name">公告内容</label>
		  			<span class="cont_style">
		  			<textarea rows="5" cols="50" name="content_msg" id="content_msg"></textarea>
		  			</span>
		  		</li>
		 	</ul>
	 	</div>
	</form>
</div>
</body>
</html>

<script type="text/javascript">
//初始化宽度、高度  
 $(".widget-box").height($(window).height()); 
 $(".Ads_list").width($(window).width()-220);
  //当文档窗口发生改变时 触发  
    $(window).resize(function(){
	$(".widget-box").height($(window).height());
	 $(".Ads_list").width($(window).width()-220);
	});
	$(function() { 
	$("#advertising").fix({
		float : 'left',
		//minStatue : true,
		skin : 'green',	
		durationTime :false,
		stylewidth:'220',
		spacingw:30,//设置隐藏时的距离
	    spacingh:250,//设置显示时间距
		set_scrollsidebar:'.Ads_style',
		table_menu:'.Ads_list'
	});
});
/*公告信息-锁定*/
function member_stop(obj,id){
	layer.confirm('确认要锁定吗？',{icon:0,},function(index){
		$(obj).parents("tr").find(".ace").prop("checked",false).attr("disabled","disabled");
		$(obj).next().remove();
		$(obj).next().remove();
		$(obj).after('<a title="编辑" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a> <a title="删除" href="javascript:;"  class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs " onClick="member_start(this,id)" href="javascript:;" title="显示"><i class="fa fa-close bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已锁定</span>');
		$(obj).remove();
		layer.msg('锁定完成!',{icon: 5,time:1000});
	});
}
/*<a title="编辑" onclick="member_edit(this,'550')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a>      
  <a title="删除" href="noticesServlet?notices_id=${notices.notices_id }&opr=del"  onclick="return confirm('你确定要删除吗')" class="btn btn-xs btn-warning" >
  <i class="fa fa-trash  bigger-120"></i></a>*/

/*公告信息-解锁*/
function member_start(obj,id){
	layer.confirm('确认要解锁吗？',{icon:0,},function(index){
		$(obj).parents("tr").find(".ace").removeAttr("disabled");
		$(obj).next().remove();
		$(obj).next().remove();
		$(obj).after('<a title="编辑" onclick="member_edit(this,\'550\')" href="javascript:;"  class="btn btn-xs btn-info" ><i class="fa fa-edit bigger-120"></i></a> <a title="删除"  onclick="member_del(this);" class="btn btn-xs btn-warning" ><i class="fa fa-trash  bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,id)" href="noticesServlet?notices_id=\${notices.notices_id }&opr=del" title="关闭"><i class="fa fa-check  bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已解锁</span>');
		$(obj).remove();
		layer.msg('解锁完成!',{icon: 6,time:1000});
	});
}
 
/*******删除单条公告*********/
function member_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$("#delsingleId").val($(obj).parents("tr").find(".notices_id").html());
		$("#delBySingle").submit();
		layer.close(index);	
	});
}
/*******添加公告*********/
 $('#ads_add').on('click', function(){
	 $("input[name='opr']").val("add");
	  layer.open({
        type: 1,
        title: '添加公告',
		maxmin: true, 
		shadeClose: false, //点击遮罩关闭层
        area : ['800px' , ''],
        content:$('#add_ads_style'),
		btn:['提交','取消'],
		yes:function(index,layero){	
		 var num=0;
		 var str="";
    	 $(".add_adverts input[type$='text']").each(function(n){
          if($(this).val()==""||$("#noticeType_id").val()=="all")
          {
               if($("#noticeType_id").val()=="all")
            	   {
            	   layer.alert(str+=""+$("#noticeType_id").parents("li").find(".label_name").html()+"不能为空！\r\n",{
                       title: '提示框',				
       				icon:0,								
                 	}); 
            	   }
               else{
            	   layer.alert(str+=""+$(this).parents("li").find(".label_name").html()+"不能为空！\r\n",{
                       title: '提示框',				
       				icon:0,								
                 }); 
               }
			   
		    num++;
            return false;            
          } 
		 });
		  if(num>0){  return false;}	 	
          else{
        	  $("#addForm").submit();
			  layer.close(index);	
		  }		  		     				
		}
    });
});

/*******修改公告（显示默认值）*********/
function member_edit(obj,id){
	$("input[name='opr']").val("update");
	$("#notices_id").val($(obj).parents("tr").find(".notices_id").html());
	$("#noticeType_id").val($(obj).parents("tr").find(".noticetype").find("p").html());
	$("#titles").val($(obj).parents("tr").find(".titles").html());
	$("#content_msg").val($(obj).parents("tr").find(".content_msg").html());
	$("#create_date").val($(obj).parents("tr").find(".create_date").html());
	  layer.open({
        type: 1,
        title: '修改公告',
		maxmin: true, 
		shadeClose:false, //点击遮罩关闭层
        area : ['800px' , ''],
        content:$('#add_ads_style'),
		btn:['提交','取消'],
		yes:function(index,layero){	
		 var num=0;
		 var str="";
     $(".add_menber input[type$='text']").each(function(n){
    	 if($(this).val()==""||$("#noticeType_id").val()=="all")
         {
              if($("#noticeType_id").val()=="all")
           	   {
           	   layer.alert(str+=""+$("#noticeType_id").parents("li").find(".label_name").html()+"不能为空！\r\n",{
                      title: '提示框',				
      				icon:0,								
                	}); 
           	   }
              else{
           	   layer.alert(str+=""+$(this).parents("li").find(".label_name").html()+"不能为空！\r\n",{
                      title: '提示框',				
      				icon:0,								
                }); 
              }
			   
		    num++;
           return false;            
         } 
		 });
		  if(num>0){  return false;}	 	
          else{
        	  $("#addForm").submit();
			   layer.close(index);	
		  }		  		     				
		}
    });
}


</script>

<script>
//加载datatable
jQuery(function($) {
var oTable1 = $('#sample-table').dataTable( {
"aaSorting": [[ 1, "desc" ]],//默认第几个排序
"bStateSave": true,//状态保存
"aoColumnDefs": [
  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
  {"orderable":false,"aTargets":[0,2,6,7]}// 制定列不参与排序
		] } );
		
	$('table th input:checkbox').on('click' , function(){
		var that = this;
		$(this).closest('table').find('tr > td:first-child input:checkbox')
		.each(function(){
			this.checked = that.checked;
			$(this).closest('tr').toggleClass('selected');
		});
			
	});

	$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});

	function tooltip_placement(context, source) {
		var $source = $(source);
		var $parent = $source.closest('table');
		var off1 = $parent.offset();
		var w1 = $parent.width();

		var off2 = $source.offset();
		var w2 = $source.width();

		if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
		return 'left';
	}
});
</script>
